<?php
/*
 * @package		Joomla.Framework
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 *
 * @component Phoca Component
 * @copyright Copyright (C) Jan Pavelka www.phoca.cz
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License version 2 or later;
 */
defined('_JEXEC') or die();
jimport( 'joomla.application.component.view' );
class PhocaGuestbookCpViewPhocaGuestbooks extends JView
{
	protected $items;
	protected $pagination;
	protected $state;
	
	function display($tpl = null) {
		
		$this->items		= $this->get('Items');
		$this->pagination	= $this->get('Pagination');
		$this->state		= $this->get('State');

		JHTML::stylesheet('administrator/components/com_phocaguestbook/assets/phocaguestbook.css' );
		
		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
			JError::raiseError(500, implode("\n", $errors));
			return false;
		}
		
		$this->addToolbar();
		parent::display($tpl);
		
	}
	
	
	/*
	
	
	function display($tpl = null) {
		
		global $mainframe;
		$db			=& JFactory::getDBO();
		$uri		=& JFactory::getURI();
		JHTML::stylesheet( 'phocaguestbook.css', 'administrator/components/com_phocaguestbook/assets/' );

		//Filter
		$context			= 'com_phocaguestbook.phocaguestbook.list.';
		$filter_state		= $mainframe->getUserStateFromRequest( $context.'filter_state',		'filter_state',		'',				'word' );
	#	$filter_catid		= $mainframe->getUserStateFromRequest( $context.'filter_catid',		'filter_catid',		0,				'int' );
		$filter_guestbook	= $mainframe->getUserStateFromRequest( $context.'filter_guestbook',	'filter_guestbook',	0,				'int' );
		$filter_order		= $mainframe->getUserStateFromRequest( $context.'filter_order',		'filter_order',		'a.ordering',	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $context.'filter_order_Dir',	'filter_order_Dir',	'',				'word' );
		$search				= $mainframe->getUserStateFromRequest( $context.'search',			'search',			'',				'string' );
		$search				= JString::strtolower( $search );

		// Get data from the model
		$items		= & $this->get( 'Data');
		$total		= & $this->get( 'Total');
		$pagination = & $this->get( 'Pagination' );
		
	#	// build list of categories
	#	$javascript 	= 'onchange="document.adminForm.submit();"';
	#	$lists['catid'] = JHTML::_('list.category',  'filter_catid', $context, intval( $filter_catid ), $javascript );

		//build the list of guestbooks
		$query = 'SELECT a.title AS text, a.id AS value'
		. ' FROM #__phocaguestbook_books AS a'
		. ' WHERE a.published = 1'
		. ' ORDER BY a.ordering';
		$db->setQuery( $query );
		$guestbooks = $db->loadObjectList();
		array_unshift($guestbooks, JHTML::_('select.option', '0', '- '.JText::_('Select Guestbook').' -', 'value', 'text'));
		
		//list guestbook
		$lists['guestbook'] = JHTML::_( 'select.genericlist', $guestbooks, 'filter_guestbook',  'onchange="document.adminForm.submit();"', 'value', 'text', intval( $filter_guestbook ));
		
		// state filter
		$lists['state']	= JHTML::_('grid.state',  $filter_state );

		// table ordering
		$lists['order_Dir'] = $filter_order_Dir;
		$lists['order'] = $filter_order;

		// search filter
		$lists['search']= $search;
		
		$this->assignRef('user',		JFactory::getUser());
		$this->assignRef('lists',		$lists);
		$this->assignRef('items',		$items);
		$this->assignRef('pagination',	$pagination);
		$this->assignRef('request_url',	$uri->toString());

		$this->addToolbar();
		parent::display($tpl);
		
	}*/
	
	function addToolbar() {
	
		require_once JPATH_COMPONENT.'/helpers/phocaguestbooks.php';
	
		$state	= $this->get('State');
		$canDo	= PhocaGuestbooksHelper::getActions($state->get('filter.item_id'));
	
		JToolBarHelper::title( JText::_( 'COM_PHOCAGUESTBOOK_ITEMS' ), 'item.png' );
	
		if ($canDo->get('core.create')) {
			JToolBarHelper::addNew('phocaguestbookb.add','JTOOLBAR_NEW');
		}
	
		if ($canDo->get('core.edit')) {
			JToolBarHelper::editList('phocaguestbookb.edit','JTOOLBAR_EDIT');
		}
		if ($canDo->get('core.edit.state')) {

			JToolBarHelper::divider();
			JToolBarHelper::custom('phocaguestbookbs.publish', 'publish.png', 'publish_f2.png','JTOOLBAR_PUBLISH', true);
			JToolBarHelper::custom('phocaguestbookbs.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
		}
	
		if ($canDo->get('core.delete')) {
			JToolBarHelper::deleteList( 'COM_PHOCAGUESTBOOK_WARNING_DELETE_ITEMS', 'phocaguestbooks.delete', 'COM_PHOCAGUESTBOOK_DELETE');
		}
		JToolBarHelper::divider();
		JToolBarHelper::help( 'screen.phocaguestbook', true );
	}

}
?>